﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLKDS.DTO;

namespace QLKDS.DAL
{
    public class RewardedManager
    {
        public RewardedInfo GetRewardedById(int id)
        {
            using (var db = new QLKDSDataContext())
            {
                var queryRewarded = from d in db.Rewardeds
                                    where d.Id.Equals(id)
                                    select new RewardedInfo { Id = d.Id,EmployeeId=d.EmployeeId,Reason=d.Reason,Method=d.Method};

                return queryRewarded.First();
            }
        
        }


        public IList<RewardedInfo> ListRewarded()
        {
            using (var db = new QLKDSDataContext())
            {
                var queryRewarded = from d in db.Rewardeds
                                      select new RewardedInfo { Id = d.Id, EmployeeId = d.EmployeeId, Reason = d.Reason, Method = d.Method };

                return queryRewarded.ToList();
            }
        }
    

        public void CreateRewarded(Rewarded Rewarded)
        {
            using (var db = new QLKDSDataContext())
            {
                db.Rewardeds.InsertOnSubmit(Rewarded);

                db.SubmitChanges();
               
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Rewarded"></param>
        public void UpdateRewarded(Rewarded Rewarded)
        {
            using (var db = new QLKDSDataContext())
            {
                var _Rewarded = db.Rewardeds.Single(d => d.Id.Equals(Rewarded.Id));

                _Rewarded.Reason = Rewarded.Reason;
                _Rewarded.Method = Rewarded.Method;
                _Rewarded.Description = Rewarded.Description;
                db.SubmitChanges();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        public void DeleteRewarded(int id)
        {
            using (var db = new QLKDSDataContext())
            {
                var _Rewarded = db.Rewardeds.Single(d => d.Id.Equals(id));

                db.Rewardeds.DeleteOnSubmit(_Rewarded);
                db.SubmitChanges();
            }
        }

     
    }
}
